package infoPackage;

import java.io.File;
import algorithms.GeneticAlgorithm;

public class Application {

	public static void main(String args[]){
		
		int nChromo = 10;
		
		LoadInfo loadinfo = new LoadInfo();
		loadinfo.xmlParser(initFile(args));
		System.out.println("");
		
		GeneticAlgorithm genetics = new GeneticAlgorithm(loadinfo.nSections, loadinfo.rivers, loadinfo.sections, nChromo);
		
		if((genetics.elitismNum % 2)== 1 && genetics.elitism){
			System.out.println("Invalid elistism number. Must be even. The application will exit.");
			System.exit(-3);
		}
		

		genetics.printPopulation(genetics.chromosomes);
	
		for(int i = 0; i<4; i++){
			genetics.nextGeneration();	
		}
		System.out.println("************************* Final Popuplation ***********************\n");
		genetics.printPopulation(genetics.chromosomes);
	}

	public static File initFile(String args[]){
		if (args.length == 0) {
			//System.out.println("Configuration file not specified. Program will exit.");
			//System.exit(-1);
			File file = new File("Rivers.xml");
			return file;
		}
		if (args.length == 1) {
			String currentDir = System.getProperty("user.dir");
			System.out.println(currentDir);
			File file = new File(args[0]);
			return file;
		}
		return null;
	}

}
